package com.imut.lagain.service.impl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.imut.lagain.entity.AnxietySession;
import com.imut.lagain.entity.BreathingExercise;
import com.imut.lagain.entity.SensoryExercise;
import com.imut.lagain.entity.ThoughtAnalysis;
import com.imut.lagain.repository.AnxietySessionRepository;
import com.imut.lagain.repository.BreathingExerciseRepository;
import com.imut.lagain.repository.SensoryExerciseRepository;
import com.imut.lagain.repository.ThoughtAnalysisRepository;
import com.imut.lagain.service.IAnxietyReliefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 焦虑安抚空间服务实现类
 */
@Service
public class AnxietyReliefServiceImpl implements IAnxietyReliefService {
    private static final Logger log = LoggerFactory.getLogger(AnxietyReliefServiceImpl.class);


    @Autowired
    private AnxietySessionRepository anxietySessionRepository;

    @Autowired
    private BreathingExerciseRepository breathingExerciseRepository;

    @Autowired
    private SensoryExerciseRepository sensoryExerciseRepository;

    @Autowired
    private ThoughtAnalysisRepository thoughtAnalysisRepository;
    private static final String BREATHING_478 = "4-7-8";
    private static final String BREATHING_BOX = "box_breathing";
    private static final String BREATHING_DEEP = "deep_breathing";
    private static final String SENSE_SIGHT = "sight";
    private static final String SENSE_SOUND = "sound";
    private static final String SENSE_TOUCH = "touch";
    private static final String SENSE_SMELL = "smell";
    private static final String SENSE_TASTE = "taste";

    @Override
    public AnxietySession startAnxietySession(Long userId, Integer anxietyLevel, List<String> triggers) {
        AnxietySession session = new AnxietySession();
        session.setUserId(userId);
        session.setSessionId("session_" + System.currentTimeMillis());
        session.setInitialAnxietyLevel(anxietyLevel);
        session.setTriggers(String.join(",", triggers));
        session.setStartTime(LocalDateTime.now());
        session.setStatus("active");
        
        anxietySessionRepository.insert(session);
        return session;
    }

    @Override
    public BreathingExercise getBreathingExercise(Long userId, Integer anxietyLevel, Integer duration) {
        String exerciseType = determineBreathingType(anxietyLevel);
        
        BreathingExercise exercise = new BreathingExercise();
        exercise.setUserId(userId);
        exercise.setExerciseType(exerciseType);
        // 根据练习类型设置各个阶段的时长
        setExerciseDurations(exercise, exerciseType, duration);
        exercise.setCreatedAt(LocalDateTime.now());
        
        breathingExerciseRepository.insert(exercise);
        return exercise;
    }

    @Override
    public Map<String, Object> startBreathingGuidance(Long sessionId, String exerciseType) {
        Map<String, Object> guidance = new HashMap<>();
        guidance.put("sessionId", sessionId);
        guidance.put("exerciseType", exerciseType);
        guidance.put("inhaleCount", getInhaleCount(exerciseType));
        guidance.put("holdCount", getHoldCount(exerciseType));
        guidance.put("exhaleCount", getExhaleCount(exerciseType));
        guidance.put("pauseCount", getPauseCount(exerciseType));
        guidance.put("instructions", getBreathingInstructions(exerciseType));
        guidance.put("backgroundMusic", getBreathingMusic(exerciseType));
        guidance.put("visualCues", getVisualCues(exerciseType));
        
        return guidance;
    }

    @Override
    public Boolean recordBreathingProgress(Long sessionId, Integer cyclesCompleted, Integer effectivenessRating) {
        try {
            AnxietySession session = anxietySessionRepository.findBySessionId(sessionId).orElse(null);
            if (session != null) {
                session.setBreathingCycles(cyclesCompleted);
                session.setBreathingEffectiveness(effectivenessRating);
                anxietySessionRepository.updateById(session);
                return true;
            }
            return false;
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public BreathingExercise startBreathingExercise(Long userId, Long sessionId, String exerciseType, Integer duration, Integer anxietyLevel) {
        BreathingExercise exercise = new BreathingExercise();
        exercise.setUserId(userId);
        exercise.setSessionId(String.valueOf(sessionId));
        exercise.setExerciseType(exerciseType);
        // 根据练习类型设置各个阶段的时长
        setExerciseDurations(exercise, exerciseType, duration);
        exercise.setCreatedAt(LocalDateTime.now());
        exercise.setStatus("active");
        
        breathingExerciseRepository.insert(exercise);
        return exercise;
    }

    @Override
    public Boolean updateBreathingProgress(Long exerciseId, Integer cyclesCompleted, Integer currentAnxietyLevel) {
        try {
            BreathingExercise exercise = breathingExerciseRepository.selectById(exerciseId);
            if (exercise != null) {
                exercise.setCompletedCycles(cyclesCompleted);
                exercise.setUpdatedAt(LocalDateTime.now());
                breathingExerciseRepository.updateById(exercise);
                return true;
            }
            return false;
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public Map<String, Object> completeBreathingExercise(Long exerciseId) {
        Map<String, Object> result = new HashMap<>();
        try {
            BreathingExercise exercise = breathingExerciseRepository.selectById(exerciseId);
            if (exercise != null) {
                exercise.setStatus("completed");
                exercise.setEndTime(LocalDateTime.now());
                breathingExerciseRepository.insert(exercise);
                
                result.put("success", true);
                result.put("exerciseId", exerciseId);
                result.put("cyclesCompleted", exercise.getCompletedCycles());
                result.put("improvementScore", calculateImprovementScore(exercise));
                result.put("message", "呼吸练习完成！你做得很好。");
            } else {
                result.put("success", false);
                result.put("message", "练习记录未找到");
            }
        } catch (Exception e) {
            result.put("success", false);
            result.put("message", "完成练习时发生错误");
        }
        return result;
    }

    @Override
    public Map<String, Object> completeAnxietySession(Long sessionId, Integer finalAnxietyLevel, String feedback) {
        return completeSession(sessionId, finalAnxietyLevel, feedback);
    }

    @Override
    public List<AnxietySession> getComfortHistory(Long userId, String startDate, String endDate) {
        try {
            LocalDateTime start = startDate != null ? LocalDateTime.parse(startDate + "T00:00:00") : LocalDateTime.now().minusDays(30);
            LocalDateTime end = endDate != null ? LocalDateTime.parse(endDate + "T23:59:59") : LocalDateTime.now();
            return anxietySessionRepository.findByUserIdAndDateRange(userId, start, end);
        } catch (Exception e) {
            return anxietySessionRepository.findByUserId(userId);
        }
    }

    @Override
    public SensoryExercise getSensoryExercise(Long userId, String senseType, String environment) {
        SensoryExercise exercise = new SensoryExercise();
        exercise.setUserId(userId);
        exercise.setSenseFocus(senseType);
        exercise.setEnvironmentDescription(environment);
        exercise.setExerciseType("5-4-3-2-1");
        exercise.setCreatedAt(LocalDateTime.now());
        
        sensoryExerciseRepository.insert(exercise);
        return exercise;
    }

    @Override
    public Map<String, Object> start54321Exercise(Long sessionId) {
        Map<String, Object> exercise = new HashMap<>();
        exercise.put("sessionId", sessionId);
        exercise.put("title", "5-4-3-2-1 感官接地练习");
        exercise.put("description", "通过五种感官帮助你回到当下，缓解焦虑");
        
        List<Map<String, Object>> steps = Arrays.asList(
            createSensoryStep("看", 5, "找到5样你能看到的东西", Arrays.asList("墙上的画", "桌上的杯子", "窗外的树", "手机屏幕", "自己的手")),
            createSensoryStep("听", 4, "找到4种你能听到的声音", Arrays.asList("空调声", "远处的车声", "自己的呼吸声", "键盘敲击声")),
            createSensoryStep("触", 3, "找到3样你能触摸到的东西", Arrays.asList("椅子的材质", "桌面的温度", "衣服的质感")),
            createSensoryStep("闻", 2, "找到2种你能闻到的气味", Arrays.asList("空气清新剂", "咖啡香味")),
            createSensoryStep("尝", 1, "找到1种你能尝到的味道", Arrays.asList("口中的薄荷味"))
        );
        
        exercise.put("steps", steps);
        exercise.put("totalDuration", 10); // 预计10分钟
        
        return exercise;
    }

    @Override
    public Boolean recordSensoryResult(Long sessionId, String senseType, List<String> items, Integer effectiveness) {
        try {
            AnxietySession session = anxietySessionRepository.findBySessionId(sessionId).orElse(null);
            if (session != null) {
                String sensoryData = session.getSensoryData();
                Map<String, Object> data = sensoryData != null ? parseJsonString(sensoryData) : new HashMap<>();
                data.put(senseType, Map.of("items", items, "effectiveness", effectiveness));
                session.setSensoryData(mapToJsonString(data));
                anxietySessionRepository.insert(session);
                return true;
            }
            return false;
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public ThoughtAnalysis startThoughtAnalysis(Long sessionId, String anxiousThought) {
        ThoughtAnalysis analysis = new ThoughtAnalysis();
        analysis.setSessionId(String.valueOf(sessionId));
        analysis.setThoughtContent(anxiousThought);
        analysis.setAnxietyLevel("moderate");
        analysis.setCreatedAt(LocalDateTime.now());
        analysis.setStatus("active");
        
        thoughtAnalysisRepository.insert(analysis);
        return analysis;
    }

    @Override
    public Map<String, Object> performCognitiveRestructuring(Long analysisId, Map<String, String> answers) {
        Map<String, Object> restructuring = new HashMap<>();
        String evidence = answers.get("evidence");
        String alternatives = answers.get("alternatives");
        String worstCase = answers.get("worstCase");
        String coping = answers.get("coping");
        List<String> suggestions = new ArrayList<>();
        suggestions.add("基于你提供的证据，这个想法可能不完全准确");
        suggestions.add("考虑其他可能的解释：" + alternatives);
        suggestions.add("即使最坏的情况发生，你也有应对方法：" + coping);
        
        restructuring.put("analysisId", analysisId);
        restructuring.put("suggestions", suggestions);
        restructuring.put("balancedThought", generateBalancedThought(answers));
        restructuring.put("copingStrategies", generateCopingStrategies(answers));
        
        return restructuring;
    }

    @Override
    public List<String> generateAlternativeThoughts(Long analysisId, String originalThought) {
        List<String> alternatives = new ArrayList<>();
        alternatives.add("也许事情没有我想象的那么糟糕");
        alternatives.add("我可能过度解读了这个情况");
        alternatives.add("这种感觉是暂时的，会过去的");
        alternatives.add("我有能力处理这个挑战");
        alternatives.add("我可以寻求帮助和支持");
        alternatives.add("这是一个学习和成长的机会");
        
        return alternatives;
    }

    @Override
    public Map<String, Object> completeSession(Long sessionId, Integer finalAnxietyLevel, String feedback) {
        AnxietySession session = anxietySessionRepository.findBySessionId(sessionId).orElse(null);
        if (session != null) {
            session.setFinalAnxietyLevel(finalAnxietyLevel);
            session.setFeedback(feedback);
            session.setEndTime(LocalDateTime.now());
            session.setStatus("completed");
            anxietySessionRepository.insert(session);
            
            Map<String, Object> summary = new HashMap<>();
            summary.put("sessionId", sessionId);
            summary.put("duration", calculateDuration(session.getStartTime(), session.getEndTime()));
            summary.put("anxietyReduction", session.getInitialAnxietyLevel() - finalAnxietyLevel);
            summary.put("effectivenessTips", generateEffectivenessTips(session));
            summary.put("nextSteps", generateNextSteps(finalAnxietyLevel));
            
            return summary;
        }
        return new HashMap<>();
    }

    @Override
    public List<String> getPersonalizedSuggestions(Long userId, String currentMood, String timeOfDay) {
        List<String> suggestions = new ArrayList<>();
        if ("anxious".equals(currentMood)) {
            suggestions.add("尝试5分钟的深呼吸练习");
            suggestions.add("进行5-4-3-2-1感官接地练习");
        }
        
        if ("morning".equals(timeOfDay)) {
            suggestions.add("开始新的一天前，做几个深呼吸");
            suggestions.add("设定今天的积极意图");
        } else if ("evening".equals(timeOfDay)) {
            suggestions.add("回顾今天的积极时刻");
            suggestions.add("进行放松练习准备睡眠");
        }
        
        return suggestions;
    }

    @Override
    public List<AnxietySession> getReliefHistory(Long userId, Integer days) {
        LocalDateTime startDate = LocalDateTime.now().minusDays(days);
        return anxietySessionRepository.findByUserIdAndStartTimeAfter(userId, startDate);
    }

    @Override
    public Map<String, Object> analyzeAnxietyPatterns(Long userId) {
        List<AnxietySession> sessions = anxietySessionRepository.findByUserId(userId);
        
        Map<String, Object> patterns = new HashMap<>();
        patterns.put("totalSessions", sessions.size());
        patterns.put("averageInitialAnxiety", calculateAverageInitialAnxiety(sessions));
        patterns.put("averageImprovement", calculateAverageImprovement(sessions));
        patterns.put("commonTriggers", findCommonTriggers(sessions));
        patterns.put("mostEffectiveTechniques", findMostEffectiveTechniques(sessions));
        patterns.put("timePatterns", analyzeTimePatterns(sessions));
        
        return patterns;
    }

    @Override
    public Map<String, Object> getProgressReport(Long userId, String period) {
        LocalDateTime startDate = getStartDateForPeriod(period);
        List<AnxietySession> sessions = anxietySessionRepository.findByUserIdAndStartTimeAfter(userId, startDate);
        
        Map<String, Object> report = new HashMap<>();
        report.put("period", period);
        report.put("totalSessions", sessions.size());
        report.put("averageImprovement", calculateAverageImprovement(sessions));
        report.put("consistencyScore", calculateConsistencyScore(sessions, period));
        report.put("progressTrend", calculateProgressTrend(sessions));
        report.put("achievements", generateAchievements(sessions));
        
        return report;
    }

    private Integer calculateImprovementScore(BreathingExercise exercise) {
        if (exercise.getAnxietyLevel() != null && exercise.getCurrentAnxietyLevel() != null) {
            int improvement = exercise.getAnxietyLevel() - exercise.getCurrentAnxietyLevel();
            return Math.max(0, improvement * 20); // 转换为0-100分
        }
        return 50; // 默认分数
    }

    @Override
    public Boolean setReliefReminder(Long userId, String reminderType, Map<String, Object> settings) {
        return true;
    }

    @Override
    public Map<String, Object> getEmergencyReliefPlan(Long userId, String severity) {
        Map<String, Object> plan = new HashMap<>();
        
        switch (severity) {
            case "mild":
                plan.put("techniques", Arrays.asList("深呼吸", "5-4-3-2-1练习"));
                plan.put("duration", 5);
                break;
            case "moderate":
                plan.put("techniques", Arrays.asList("4-7-8呼吸法", "思维拆解", "感官安抚"));
                plan.put("duration", 15);
                break;
            case "severe":
                plan.put("techniques", Arrays.asList("紧急呼吸练习", "接地技巧", "寻求专业帮助"));
                plan.put("duration", 30);
                plan.put("emergencyContacts", getEmergencyContacts());
                break;
        }
        
        plan.put("severity", severity);
        plan.put("immediateSteps", getImmediateSteps(severity));
        
        return plan;
    }
    private String determineBreathingType(Integer anxietyLevel) {
        if (anxietyLevel <= 3) return BREATHING_DEEP;
        if (anxietyLevel <= 6) return BREATHING_BOX;
        return BREATHING_478;
    }

    private Integer getInhaleCount(String exerciseType) {
        switch (exerciseType) {
            case BREATHING_478: return 4;
            case BREATHING_BOX: return 4;
            case BREATHING_DEEP: return 6;
            default: return 4;
        }
    }

    private Integer getHoldCount(String exerciseType) {
        switch (exerciseType) {
            case BREATHING_478: return 7;
            case BREATHING_BOX: return 4;
            case BREATHING_DEEP: return 2;
            default: return 4;
        }
    }

    private Integer getExhaleCount(String exerciseType) {
        switch (exerciseType) {
            case BREATHING_478: return 8;
            case BREATHING_BOX: return 4;
            case BREATHING_DEEP: return 8;
            default: return 4;
        }
    }

    private Integer getPauseCount(String exerciseType) {
        return BREATHING_BOX.equals(exerciseType) ? 4 : 0;
    }

    private String getBreathingInstructions(String exerciseType) {
        switch (exerciseType) {
            case BREATHING_478:
                return "吸气4秒，屏住呼吸7秒，呼气8秒。这种方法有助于激活副交感神经系统，快速缓解焦虑。";
            case BREATHING_BOX:
                return "吸气4秒，屏住4秒，呼气4秒，暂停4秒。想象画一个正方形，每条边对应一个步骤。";
            case BREATHING_DEEP:
                return "深深吸气6秒，短暂屏住2秒，缓慢呼气8秒。专注于腹部的起伏，让呼吸变得深长。";
            default:
                return "跟随引导进行呼吸练习，专注于呼吸的节奏。";
        }
    }

    private void setExerciseDurations(BreathingExercise exercise, String exerciseType, Integer totalDuration) {
        switch (exerciseType) {
            case BREATHING_478:
                exercise.setInhaleDuration(4);
                exercise.setHoldDuration(7);
                exercise.setExhaleDuration(8);
                exercise.setPauseDuration(0);
                break;
            case BREATHING_BOX:
                exercise.setInhaleDuration(4);
                exercise.setHoldDuration(4);
                exercise.setExhaleDuration(4);
                exercise.setPauseDuration(4);
                break;
            case BREATHING_DEEP:
                exercise.setInhaleDuration(6);
                exercise.setHoldDuration(2);
                exercise.setExhaleDuration(8);
                exercise.setPauseDuration(0);
                break;
            default:
                exercise.setInhaleDuration(4);
                exercise.setHoldDuration(4);
                exercise.setExhaleDuration(6);
                exercise.setPauseDuration(2);
                break;
        }
        // 根据总时长计算总周期数
        int cycleDuration = exercise.getInhaleDuration() + exercise.getHoldDuration() + 
                           exercise.getExhaleDuration() + exercise.getPauseDuration();
        int totalCycles = totalDuration / cycleDuration;
        exercise.setTotalCycles(totalCycles);
    }

    private String getBreathingMusic(String exerciseType) {
        return "calm_nature_sounds";
    }

    private List<String> getVisualCues(String exerciseType) {
        return Arrays.asList("呼吸球动画", "波浪动画", "颜色渐变");
    }

    private String getSensoryInstructions(String senseType, String environment) {
        return "专注于你的" + senseType + "感官，在" + environment + "环境中寻找相应的感官体验。";
    }

    private List<String> getSensoryTargets(String senseType, String environment) {
        return Arrays.asList("目标1", "目标2", "目标3");
    }

    private Map<String, Object> createSensoryStep(String sense, int count, String instruction, List<String> examples) {
        Map<String, Object> step = new HashMap<>();
        step.put("sense", sense);
        step.put("count", count);
        step.put("instruction", instruction);
        step.put("examples", examples);
        return step;
    }

    private String generateAnalysisQuestions() {
        List<String> questions = Arrays.asList(
            "这个想法有什么证据支持吗？",
            "有没有其他可能的解释？",
            "最坏的情况是什么？",
            "如果最坏的情况发生，我该如何应对？",
            "这个想法对我有帮助吗？"
        );
        return String.join("|", questions);
    }

    private String generateBalancedThought(Map<String, String> answers) {
        return "基于分析，一个更平衡的想法可能是：这种情况有多种可能的结果，我有能力应对各种情况。";
    }

    private List<String> generateCopingStrategies(Map<String, String> answers) {
        return Arrays.asList(
            "深呼吸和放松技巧",
            "寻求朋友或家人的支持",
            "专注于可控制的因素",
            "制定具体的行动计划"
        );
    }

    private long calculateDuration(LocalDateTime start, LocalDateTime end) {
        return java.time.Duration.between(start, end).toMinutes();
    }

    private List<String> generateEffectivenessTips(AnxietySession session) {
        List<String> tips = new ArrayList<>();
        if (session.getBreathingEffectiveness() != null && session.getBreathingEffectiveness() >= 4) {
            tips.add("呼吸练习对你很有效，可以经常使用");
        }
        tips.add("定期练习可以提高效果");
        return tips;
    }

    private List<String> generateNextSteps(Integer finalAnxietyLevel) {
        List<String> steps = new ArrayList<>();
        if (finalAnxietyLevel > 5) {
            steps.add("考虑进行更长时间的练习");
            steps.add("如果焦虑持续，建议寻求专业帮助");
        } else {
            steps.add("保持良好的练习习惯");
            steps.add("在日常生活中应用学到的技巧");
        }
        return steps;
    }

    private Double calculateAverageInitialAnxiety(List<AnxietySession> sessions) {
        return sessions.stream()
                .mapToInt(AnxietySession::getInitialAnxietyLevel)
                .average()
                .orElse(0.0);
    }

    private Double calculateAverageImprovement(List<AnxietySession> sessions) {
        return sessions.stream()
                .filter(s -> s.getFinalAnxietyLevel() != null)
                .mapToInt(s -> s.getInitialAnxietyLevel() - s.getFinalAnxietyLevel())
                .average()
                .orElse(0.0);
    }

    private List<String> findCommonTriggers(List<AnxietySession> sessions) {
        Map<String, Long> triggerCounts = sessions.stream()
                .filter(s -> s.getTriggers() != null)
                .flatMap(s -> Arrays.stream(s.getTriggers().split(",")))
                .collect(Collectors.groupingBy(t -> t, Collectors.counting()));
        
        return triggerCounts.entrySet().stream()
                .sorted(Map.Entry.<String, Long>comparingByValue().reversed())
                .limit(5)
                .map(Map.Entry::getKey)
                .collect(Collectors.toList());
    }

    private List<String> findMostEffectiveTechniques(List<AnxietySession> sessions) {
        return Arrays.asList("深呼吸", "5-4-3-2-1练习", "思维拆解");
    }

    private Map<String, Object> analyzeTimePatterns(List<AnxietySession> sessions) {
        Map<String, Object> patterns = new HashMap<>();
        patterns.put("mostCommonHour", "14:00-16:00");
        patterns.put("mostCommonDay", "Monday");
        return patterns;
    }

    private LocalDateTime getStartDateForPeriod(String period) {
        switch (period) {
            case "week": return LocalDateTime.now().minusWeeks(1);
            case "month": return LocalDateTime.now().minusMonths(1);
            case "quarter": return LocalDateTime.now().minusMonths(3);
            default: return LocalDateTime.now().minusWeeks(1);
        }
    }

    private Double calculateConsistencyScore(List<AnxietySession> sessions, String period) {
        int expectedSessions = getExpectedSessionsForPeriod(period);
        return Math.min(100.0, (sessions.size() * 100.0) / expectedSessions);
    }

    private int getExpectedSessionsForPeriod(String period) {
        switch (period) {
            case "week": return 7;
            case "month": return 30;
            case "quarter": return 90;
            default: return 7;
        }
    }

    private String calculateProgressTrend(List<AnxietySession> sessions) {
        if (sessions.size() < 2) return "insufficient_data";
        
        List<AnxietySession> recentSessions = sessions.stream()
                .sorted((a, b) -> b.getStartTime().compareTo(a.getStartTime()))
                .limit(5)
                .collect(Collectors.toList());
        
        double avgImprovement = calculateAverageImprovement(recentSessions);
        
        if (avgImprovement > 2) return "improving";
        if (avgImprovement > 0) return "stable";
        return "needs_attention";
    }

    private List<String> generateAchievements(List<AnxietySession> sessions) {
        List<String> achievements = new ArrayList<>();
        
        if (sessions.size() >= 7) {
            achievements.add("坚持练习一周");
        }
        if (sessions.size() >= 30) {
            achievements.add("坚持练习一个月");
        }
        
        double avgImprovement = calculateAverageImprovement(sessions);
        if (avgImprovement >= 3) {
            achievements.add("焦虑缓解效果显著");
        }
        
        return achievements;
    }

    private List<String> getEmergencyContacts() {
        return Arrays.asList(
            "心理危机干预热线：400-161-9995",
            "全国心理援助热线：400-161-9995"
        );
    }

    private List<String> getImmediateSteps(String severity) {
        switch (severity) {
            case "mild":
                return Arrays.asList("找一个安静的地方", "开始深呼吸", "专注于当下");
            case "moderate":
                return Arrays.asList("停止当前活动", "进行呼吸练习", "使用接地技巧", "联系信任的人");
            case "severe":
                return Arrays.asList("确保安全", "立即进行呼吸练习", "联系紧急联系人", "考虑寻求专业帮助");
            default:
                return Arrays.asList("保持冷静", "深呼吸");
        }
    }
    private Map<String, Object> parseJsonString(String jsonString) {
        return new HashMap<>();
    }

    private String mapToJsonString(Map<String, Object> map) {
        return "{}";
    }
}
